﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MachineVision.Core;
using MachineVision.Extensions;
using MachineVision.Models;
using MachineVision.Shared.Events;
using Prism.Commands;
using Prism.Events;
using Prism.Regions;

namespace MachineVision.ViewModels
{
    public class SettingViewModel : NavigationViewModel
    {
        public SettingViewModel(IEventAggregator aggregator)
        {
            LanguageInfos = new ObservableCollection<LanguageInfo>();
            this.aggregator = aggregator;
        }
        public override void OnNavigatedTo(NavigationContext navigationContext)
        {
            InitLanguageSetting();
            base.OnNavigatedTo(navigationContext);
        }

        void InitLanguageSetting()
        {
            LanguageInfos?.Clear();
            LanguageInfos.Add(new LanguageInfo() { Key = "中文", Value = "zh_CN" });
            LanguageInfos.Add(new LanguageInfo() { Key = "English", Value = "en_US" });
        }

        private DelegateCommand<object> _cmdSaveSettings;
        public DelegateCommand<object> CmdSaveSettings => _cmdSaveSettings ??= new DelegateCommand<object>((param) =>
        {

        });

        private string _currentSkin;
        //当前主题色
        public string CurrentSkin
        {
            get { return _currentSkin; }
            set { SetProperty(ref _currentSkin, value); OnSkinChanged(value); }
        }

        private void OnSkinChanged(string value)
        {
            SkinHelper.SetSkin(value);
        }

        private LanguageInfo _selectLanguage;

        public LanguageInfo SelectLanguage
        {
            get { return _selectLanguage; }
            set { SetProperty(ref _selectLanguage, value); OnLanguageChanged(value?.Value); }
        }

        void OnLanguageChanged(string key)
        {
            if (string.IsNullOrEmpty(key)) return;
            LanguageHelper.SetLanguage(key);
            aggregator.GetEvent<LanguageEventBus>().Publish(true);

        }

        private ObservableCollection<LanguageInfo> _languageinfos;
        private readonly IEventAggregator aggregator;

        public ObservableCollection<LanguageInfo> LanguageInfos
        {
            get { return _languageinfos; }
            set { SetProperty(ref _languageinfos, value); }
        }
    }
}
